define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'role/member/index' + location.search,
                    add_url: 'role/member/add',
                    edit_url: 'role/member/edit',
                    del_url: 'role/member/del',
                    multi_url: 'role/member/multi',
                    table: 'member',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'phone', title: __('Phone'), operate: 'LIKE'},
                        {field: 'nick_name', title: __('Nick_name'), operate: 'LIKE'},
                        {field: 'member_name', title: __('Member_name'), operate: 'LIKE'},
                        {field: 'member_img', title: __('Member_img'), formatter: Table.api.formatter.image, operate: false},
                        // {field: 'sale', title: __('Sale')},
                        // {field: 'password', title: __('Password')},
                        // {field: 'company_id', title: __('Company_id')},
                        {field: 'company_name', title: __('Company_name'), operate: 'LIKE'},
                        {field: 'station.name', title: __('Station_id'), operate: 'LIKE'},
                        {field: 'card_number', title: __('Card_number'), operate: 'LIKE'},
                        {field: 'card_front', title: __('Card_front'), formatter: Table.api.formatter.image, operate: false},
                        {field: 'card_reverse', title: __('Card_reverse'), formatter: Table.api.formatter.image, operate: false},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'sell.name', title: __('Sell_id')},
                        {field: 'sell_phone', title: __('Sell_phone'), operate: 'LIKE'},
                        {field: 'sell_name', title: __('Sell_name'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function (value, row, index) {
                            var that = $.extend({}, this);
                            var table = $(that.table).clone(true);
                            $(table).data("operate-del", null);
                            that.table = table;
                            return Table.api.formatter.operate.call(that, value, row, index);
                        }}
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});